<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">


    <title>登录</title>


    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">


    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/iCheck/square/blue.css">
</head>

<body class="hold-transition login-page">
<div class="login-box" id="app">
    <div class="login-logo">

        <a href=""><b>指针旅游</b>后台管理系统</a>

    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">登录系统</p>

        <form action="" method="get">
            <div class="form-group has-feedback">
                <input v-model="email" type="email" class="form-control" placeholder="Email">
                <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            </div>
            <div class="form-group has-feedback">
                <input v-model="password" type="password" class="form-control" placeholder="密码">
                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            </div>
            <div class="row">
                <div id="errorDiv"></div>
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label><input type="checkbox"> 记住 下次自动登录</label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-xs-4">
                    <button type="button" @click="login()" class="btn btn-primary btn-block btn-flat">登录</button>
                </div>
                <!-- /.col -->
            </div>
        </form>


        <!-- /.social-auth-links -->

        <a href="#">忘记密码</a><br>

    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 2.2.3 -->
<!-- Bootstrap 3.3.6 -->
<!-- iCheck -->
<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="../plugins/iCheck/icheck.min.js"></script>
<script>
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });
</script>

<script src="../js/vue.js"></script>
<script src="../js/axios.js"></script>
<script>
    const app = new Vue({
        el: "#app",
        data: {
            // 默认初始值，上面input，通过v-model绑定值
            email: "",
            password: ""
        },
        methods: {
            login() {
                // 发送ajax的post请求
                /*
                    post方法：
                     1.第一个参数：请求路径
                     2.第二个参数：请求参数本身，请求体中
                     3.第三个参数：请求配置，包含请求头等
                 */
                axios.post("/user/login",
                    {email: this.email, password: this.password})
                    // .then(function(response) {
                    //     console.log(response.data);
                    //     if (response.data.flag) {
                    //         // 成功
                    //         location.href = '/pages/index.html';
                    //     } else {
                    //         $("#errorDiv").html(response.data.errorMsg);
                    //     }
                    // });
                    .then((response) => {
                        if (response.data.flag) {
                                    // 成功
                                    location.href = '/pages/index.html?username=' + response.data.data.username;
                                } else {
                                    $("#errorDiv").html(response.data.errorMsg);
                                }
                    });
                // get请求的参数在请求行中(url)传递的
                /*axios.get("/user/login", {params: {email: "aa@163.com", password: "1234"}}
                   )
                    .then(function(response) {
                        console.log(response.data);
                    });*/
            }
        }
    });
</script>


</body>

</html>